import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:graduation_project/cartoon_module/vertical_list.dart';

class search_state_yes extends StatefulWidget {
  const search_state_yes({Key key}) : super(key: key);

  @override
  State<search_state_yes> createState() => _search_state_yesState();
}

class _search_state_yesState extends State<search_state_yes> {
  List cartoon_tage = [
    {'tage_name': '全部', 'state': 1},
    {'tage_name': '热血', 'state': 0},
    {'tage_name': '玄幻', 'state': 0},
    {'tage_name': '奇幻', 'state': 0},
    {'tage_name': '冒险', 'state': 0},
    {'tage_name': '都市', 'state': 0},
    {'tage_name': '历史', 'state': 0},
    {'tage_name': '青春', 'state': 0},
    {'tage_name': '热血', 'state': 0},
    {'tage_name': '玄幻', 'state': 0},
    {'tage_name': '奇幻', 'state': 0},
    {'tage_name': '冒险', 'state': 0},
    {'tage_name': '都市', 'state': 0},
    {'tage_name': '历史', 'state': 0},
    {'tage_name': '青春', 'state': 0},
  ];

  List sortord_list = [
    {'sortord_name': '人气推荐', 'state': 1},
    {'sortord_name': '更新时间', 'state': 0},
    {'sortord_name': '追漫人数', 'state': 0},
    {'sortord_name': '上架时间', 'state': 0},
  ];
  List _search_list = [
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
  ];
  List _search_list1 = [
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
    {
      'cartoon': 1007,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'author': '尾田荣一郎',
      'tage': '都市',
      'stae': '连载中'
    },
  ];
  ScrollController _scrollController = new ScrollController();
  @override
  void initState() {
    print('进入搜索');
    // TODO: implement initState
    super.initState();
    _scrollController.addListener(() {
      if (_scrollController.position.pixels ==
          _scrollController.position.maxScrollExtent) {
        // _onLoadmore();
        print('滑到了最底部');
        _search_list..addAll(_search_list1);
        // print(cartoon_list0.length);
        setState(() {});
      }

      // print(_scrollController.offset);
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    print('离开搜索');
  }

  @override
  Widget build(BuildContext context) {
    return NestedScrollView(
      controller: _scrollController,
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          SliverAppBar(
            // leading: null,
            automaticallyImplyLeading: false,
            backgroundColor: Color.fromRGBO(255, 250, 250, 1),
            expandedHeight: 130.0,
            pinned: false,
            floating: true,
            snap: true,
            // ignore: missing_return

            flexibleSpace: OverflowBox(
              maxHeight: 120,
              child: Column(
                children: [
                  Expanded(child: SizedBox()),
                  Wrap(
                    spacing: 10,
                    children: cartoon_tage
                        .map((v) => InkWell(
                              onTap: () {
                                cartoon_tage.forEach((element) {
                                  // print(element['state']);
                                  element['state'] = 0;
                                });
                                v['state'] = 1;

                                setState(() {});
                              },
                              child: Text(
                                v['tage_name'],
                                // '1',
                                style: TextStyle(
                                    color: v['state'] == 1
                                        ? Color.fromRGBO(80, 200, 255, 1)
                                        : Colors.black87),

                                // backgroundColor: Color(0xFFf2f2f2),
                              ),
                            ))
                        .toList(),
                  ),
                  Container(
                    height: 10.0,
                  ),
                  Divider(
                    height: 1.0,
                    // indent: 100.0,
                    color: Colors.black87,
                  ),
                  Container(
                    height: 10.0,
                  ),
                  Container(
                    margin: EdgeInsets.only(
                      left: 15,
                    ),
                    child: Row(children: [
                      Wrap(
                        // alignment: WrapAlignment.center,
                        spacing: 10,
                        children: sortord_list
                            .map((v) => InkWell(
                                  onTap: () {
                                    sortord_list.forEach((element) {
                                      // print(element['state']);
                                      element['state'] = 0;
                                    });
                                    v['state'] = 1;

                                    setState(() {});
                                  },
                                  child: Text(
                                    v['sortord_name'],
                                    // '1',
                                    style: TextStyle(
                                        color: v['state'] == 1
                                            ? Color.fromRGBO(80, 200, 255, 1)
                                            : Colors.black87),

                                    // backgroundColor: Color(0xFFf2f2f2),
                                  ),
                                ))
                            .toList(),
                      ),
                    ]),
                  ),
                  Container(
                    height: 30.0,
                  ),
                ],
              ),
            ),
          ),
        ];
      },
      body: RefreshIndicator(
        onRefresh: () async {
          //模拟网络请求
          print('上拉刷新');
          // print(cartoon_list0);
          await Future.delayed(Duration(milliseconds: 2000));
          //结束刷新
          return Future.value(true);
        },
        child: ListView.builder(
            // controller: _scrollController,
            itemBuilder: (BuildContext context, int index) {
          return vertical_list(
            cattoon_list: _search_list,
          );
        }),
      ),
    );
  }
}
